const http = require('http')
const fs = require('fs') // file system
// var httpProxy = require('http-proxy')
// var proxy = httpProxy.createProxyServer()

http.createServer((request, response) => {
    console.log(request.url)

    if (request.url === '/index.html') {
        fs.readFile('index.html', (err, data) => {
            response.writeHead(200, {
                'Content-type': 'text/html'
            })
            response.write(data.toString())
            response.end()
        })
    }

    if (request.url === '/favicon.ico') {
        fs.readFile('favicon.ico', (err, data) => {
            response.writeHead(200, {
                'Content-Type': 'image/x-icon'
            })
            response.write(data.toString())
            response.end()
        })
    }

    if (request.url.includes('api/login')) {
        response.writeHead(200, {
            'Set-Cookie': 'userId=6; path=/',
            'Content-Type': 'text/plain'
        })
        response.end('api/login')
    }

    if (request.url.includes('api/getUsername')) {
        console.log(request.headers.cookie)
        response.end('api/getUsername')
    }

    /*if (request.url.includes('/api')) {
        proxy.web(request, response, { target: 'http://127.0.0.1:8000' })
    }*/

}).listen(4000)



